package com.gin.no_gay_alliance.viewmodel;

import androidx.annotation.NonNull;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.gin.jackson.utils.ObjectUtils;

import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * APP的发行版信息
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/9/10 23:51
 **/
public class AppRelease {
    public int id;
    @JsonAlias("tag_name")
    public String tagName;
    @JsonAlias("prerelease")
    public boolean preRelease;
    public String name;
    /**
     * 描述正文内容
     */
    @JsonAlias("body")
    public String content;
    @JsonAlias("created_at")
    public ZonedDateTime createdAt;
    /**
     * 附件
     */
    public List<Asset> assets;

    /**
     * 查找下载链接
     *
     * @return 下载链接
     */
    @NonNull
    public List<String> findUrls() {
        if (ObjectUtils.isEmpty(assets)) {
            return new ArrayList<>();
        }
        return assets.stream()
                .filter(i -> !ObjectUtils.isEmpty(i.name))
                .map(i -> i.url)
                .filter(url -> url.endsWith("apk"))
                .collect(Collectors.toCollection(ArrayList::new));
    }

    /**
     * 附件
     */
    public static class Asset {
        /**
         * 下载地址
         */
        @JsonAlias("browser_download_url")
        public String url;
        public String name;
    }
}
